@NonCPS
def getChangeFiles(build){
    def changeSets = build.changeSets
    def changeFiles=""
    if(!changeSets){
        echo "build #$build.number no changes!"
        return ""
    }else{
        echo "build #$build.number changed files!"
        def entries = changeSets[0].items
            for (int i = 0; i < entries.length; i++) {
                def entry = entries[i]
                def commitTime = new Date(entry.timestamp).format("yyyy-MM-dd HH:mm:ss")
                println("commitId: "+entry.commitId+" -- commitTime: ["+commitTime+"] -- author: ["+entry.author+"] -- commitMsg: ["+entry.msg.take(100)+"]")
                def files = new ArrayList(entry.affectedFiles)
                for (int j = 0; j < files.size(); j++) {
                    def file = files[j]
                    echo "editType.name: [${file.editType.name}] -- file.path: [${file.path}]"
                    changeFiles +=" ${file.path}"
                }
            }
        return changeFiles
    }

}

def call() {
    echo "Gathering SCM changes"
    def changeFiles=""
    def build = currentBuild
    def changeSets = build.changeSets
    if (! changeSets){
        echo "current build #$build.number no changes!"
        build=build.previousBuild
        echo "checking previous build #$build.number status..."
        if(build !=null && build.result == "SUCCESS"){
            echo "previous build #$build.number is success, exiting ...."
            return changeFiles
        }else{
            while(build !=null && build.result !="SUCCESS"){
                echo "previous build #$build.number is failed."
                changeFiles+=getChangeFiles(build)
                if(build.number ==1){
                    break
                }else{
                    build=build.previousBuild
                }

            }
            echo "finally find success build #$build.number or no success build exiting!"
            return changeFiles
        }

    }
    else{
        echo "current build #$build.number changed files!"
        changeFiles=getChangeFiles(build)
        //
        build=build.previousBuild
        echo "checking previous build #$build.number status ..."
        if(build.result == "SUCCESS"){
            echo "previous build $build.number is success, exiting ...."
            return changeFiles
        }else{
            while(build !=null && build.result !="SUCCESS"){
                changeFiles+=getChangeFiles(build)
                if(build.number ==1){
                    break
                }else{
                    build=build.previousBuild
                }
            }
            return changeFiles
        }
    }
}